package com.flame.session.config;

import com.flame.session.service.JdbcOnlineUserServiceImpl;
import com.flame.session.service.RedisOnlineUserServiceImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.session.data.redis.RedisIndexedSessionRepository;
import org.springframework.session.jdbc.JdbcIndexedSessionRepository;

@ComponentScan("com.flame.session")
@Configuration
public class FlameSessionConfiguration {

    @Bean
    @ConditionalOnProperty(prefix = "spring.session", name = "store-type", havingValue = "jdbc", matchIfMissing = true)
    public JdbcOnlineUserServiceImpl jdbcOnlineUserService() {
        return new JdbcOnlineUserServiceImpl();
    }

    @Bean
    @ConditionalOnProperty(prefix = "spring.session", name = "store-type", havingValue = "redis")
    public RedisOnlineUserServiceImpl redisOnlineUserService() {
        return new RedisOnlineUserServiceImpl();
    }
}
